import Mock from 'mockjs'

// 许可证申报
const List = []
const count = 100

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment', // 记录id
    reportingTime: +Mock.Random.date('T'), // 申报时间
    registrant: '@first', // 登记人
    leadingCadre: '@first', // 企业负责人
    'reportType|1': [1, 2], // 记录状态 1 新增  2 收贮
  }))
}

export default [
    // 许可证申报页面
    {
      url: '/addandstorage/getDelarationList',
      type: 'get',
      response: config => {
        const { page = 1, limit = 10, sort } = config.query
  
        const pageList = List.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  
        return {
          code: 200,
          data: {
            total: List.length,
            delarationList: pageList
          }
        }
      }
    },

    // 许可证申报页面
    {
      url: '/addandstorage/reportType',
      type: 'get',
      response: config => {
        // 根据企业id判断当前企业能添加什么样的表单
        const { id } = config.query
        return {
          code: 200,
          data: {
            deviceDate: [
              {
                time: "2020-02-07",
                status: "1"
              },
              {
                time: "2020-02-08",
                status: "1"
              },
              {
                time: "2020-02-09",
                status: "1"
              }
            ],
            sourceDate: [
              {
                time: "2020-02-07",
                status: "1"
              },
              {
                time: "2020-02-08",
                status: "0"
              },
              {
                time: "2020-02-09",
                status: "1"
              }
            ],
          }
        }
      }
    },

    // 查看报告的详情
    {
      url: '/addandstorage/reportDetial',
      type: 'get',
      response: config => {
        // 根据申报id查询详情
        const { id, type } = config.query;
        console.log(type, type === 1)
        const mock = type === '1' ? Mock.mock({
          "newSourceNum|1-10": 1,
        }) : Mock.mock({
          "stroageSourceNum|1-10": 1,
        })
        const num = mock.newSourceNum || mock.stroageSourceNum;
        mock.countryCode = new Array(num).fill('随机编码').join(',')
        return {
          code: 200,
          data: {
            detialData: Object.assign(mock,{
              declareTime: +Mock.Random.date('T'),
              registrant: '@first',
              chargePerson: '@first',
            }),
          }
        }
      }
    },

    // 企业详情
    {
      url: '/addandstorage/entDetial',
      type: 'get',
      response: config => {
        // 企业id
        const { id } = config.query
        return {
          code: 200,
          data: {
            // 企业的相关信息
            entData: {
              name: '@first',
              entid: '@increment',
              registrant: '@first',
              chargePerson: '@first',
              "sourceNum|1-10": 1
            },
          }
        }
      }
    },
]